using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MatchCore;
using Net.Messgae;
using pb = global::Google.Protobuf;

public class FrameHelper
{
    public static MatchCore.Frame NetFrame2MatchFrame(Net.Messgae.FrameData data)
    {
        MatchCore.Frame frame = new MatchCore.Frame();
        frame.frameId = data.FrameId;

        foreach(var playerFrame in data.Datas)
        {
            MatchCore.PlayerFrame pf = new MatchCore.PlayerFrame();
            pf.index = playerFrame.Index;
            var d = playerFrame.Data.ToByteArray();
            pf.cmd = (uint)Tools.Bytes2ULong(d,0,d.Length,false);
            frame.datas.Add(pf);
        }
        return frame;
    }

    public static Net.Messgae.PlayerFrameData MakePlayerFrameData(uint index,uint cmd)
    {
        Net.Messgae.PlayerFrameData d = new Net.Messgae.PlayerFrameData();
        d.Index = index;
        ulong value = cmd;
        byte[] buf = new byte[4];
        Tools.ULongBytes(value,buf,0,4,false);
        d.Data = pb.ByteString.CopyFrom(buf,0,4);
        return d;
    }
}